﻿using LxBasic;

namespace LxCore
{
    public class StatisticBase
    {
        public virtual AccumulationDouble RunReport(UserMonitor userMonitor, bool isConsole = false)
        {
            return AccumulationDouble.Empty;
        }
        protected IEnumerable<(FvInner, ICellVarArr<double>?, FvBound, IFaceVarArr<double>?)> getSelected(UserMonitor userMonitor, bool isCellDataStatistic, bool isFaceDataStatistic)
        {
            int ID = userMonitor.ID;
            var ScalarFinder = userMonitor.ScalarFieldFinder;
            foreach (var z in LxSim.Sim.Conditions.ZoneConds)
            {
                if (isCellDataStatistic && z.InnerCond.MonitorSelector[ID])
                {
                    yield return (z.Zone.Inner, ScalarFinder.GetCellVarArr(z.Zone.Inner), null, null);
                }
                if (isFaceDataStatistic)
                {
                    foreach (var b in z.BoundConds)
                    {
                        if (b.MonitorSelector[ID])
                        {
                            yield return (null, null, b.Bound, ScalarFinder.GetFaceVarArr(b.Bound));
                        }
                    }
                }
            }
        }

        protected void consoleItemResult(double result)
        {

        }

    }
}
//public int ID { get; set; }
//public ScalarFieldFinder ScalarFinder { get; set; } = new ScalarFieldFinder(ScalarFieldTypes.Temperature);

//public UserMonitor InMonitor;

//protected bool IsGlobalValid;
//protected double GlobalResult;
//protected bool IsLocalValid;
//protected double LocalResult;

//public virtual void GlobalIni()
//{
//    IsGlobalValid = false;
//    GlobalResult = 0;
//}
//public virtual void LocalIni()
//{
//    IsLocalValid = false;
//    LocalResult = 0;
//}
//public virtual void LocalFinish()
//{

//}
//public virtual (bool isValid, double result) GetLocalResult()
//{
//    return (IsLocalValid, LocalResult);
//}
//public virtual (bool isValid, double result) GetGlobalResult()
//{
//    return (IsGlobalValid, GlobalResult);
//}
//public virtual void StatisticCells(IIndexHost cellIdx, ICellVar<double> scalar, ICellVar<double> assistant, ThreadInfo threadInfo)
//{
//    throw new NotImplementedException();
//}
//public virtual void StatisticFaces(IIndexHost faceIdx, IFaceVar<double> scalar, IFaceVar<double> assistant, ThreadInfo threadInfo)
//{
//    throw new NotImplementedException();
//}
//protected virtual void StatisticZone(FvZone zone, IField<double> scalar, ThreadInfo threadInfo)
//{

//}
//protected virtual void StatisticThread(FvZone zone, FvBound thread, IField<double> scalar, ThreadInfo threadInfo)
//{

//}
//protected virtual void SortOutResult()
//{

//}
//public virtual void RunStatistic(bool isConsole)
//{

//}
//protected void StatisticZones(bool isConsole)
//{
//    foreach (var z in LxRes.FvMesh.Zones)
//    {
//        if (z.Inner.MonitorSelector[InMonitor.ID])
//        {
//            var scalar = z.CFDFields.GetScalar(InMonitor.ScalarType);
//            if (scalar == null) continue;
//            MultiThreads.RunMultiTasks((threadInfo) =>
//            {
//                StatisticZone(z, scalar, threadInfo);
//            });
//            if (!InMonitor.IsCurrentExist) InMonitor.IsCurrentExist = true;
//            SortOutResult();
//            if (isConsole)
//            {

//            }
//        }
//    }
//}

//protected void StatisticThreads(bool isConsole)
//{
//    foreach (var z in LxRes.FvMesh.Zones)
//    {
//        foreach (var f in z.Bounds)
//        {
//            if (f.MonitorSelector[InMonitor.ID])
//            {
//                var scalar = z.CFDFields.GetScalar(InMonitor.ScalarType);
//                if (scalar == null) continue;
//                MultiThreads.RunMultiTasks((threadInfo) =>
//                {
//                    StatisticThread(z, f, scalar, threadInfo);
//                });
//                if (!InMonitor.IsCurrentExist) InMonitor.IsCurrentExist = true;
//                SortOutResult();
//                if (isConsole)
//                {

//                }
//            }
//        }
//    }
//}
//protected void StatisticZoneThreads(bool isConsole)
//{
//    foreach (var z in LxRes.FvMesh.Zones)
//    {
//        if (z.Inner.MonitorSelector[InMonitor.ID])
//        {
//            var scalar = z.CFDFields.GetScalar(InMonitor.ScalarType);
//            if (scalar == null) continue;
//            MultiThreads.RunMultiTasks((threadInfo) =>
//            {
//                StatisticZone(z, scalar, threadInfo);
//            });
//            if (!InMonitor.IsCurrentExist) InMonitor.IsCurrentExist = true;
//            SortOutResult();
//            if (isConsole)
//            {

//            }
//        }
//        foreach (var f in z.Bounds)
//        {
//            if (f.MonitorSelector[InMonitor.ID])
//            {
//                var scalar = z.CFDFields.GetScalar(InMonitor.ScalarType);
//                if (scalar == null) continue;
//                MultiThreads.RunMultiTasks((threadInfo) =>
//                {
//                    StatisticThread(z, f, scalar, threadInfo);
//                });
//                if (!InMonitor.IsCurrentExist) InMonitor.IsCurrentExist = true;
//                SortOutResult();
//                if (isConsole)
//                {

//                }
//            }
//        }
//    }
//}
